<?php
include '../common/autoload.php';
//include '../class/MemberAccount.class.php';
//include '../class/Uploader.class.php';
$mem = new \pft\Member\MemberAccount($GLOBALS['le']);//实例化时需要注入mysql连接标识

$step = intval($_REQUEST['step']);
if ($step==1) {
    $config = array(
        "savePath"      => '../upload/'.$_SESSION['account'],
        "maxSize"       => 1024, //单位KB
        "allowFiles"    => array(".gif", ".png", ".jpg", ".jpeg", ".bmp"),
        "simpleFolder"  => true,
    );
    $up = new Uploader("upfile", $config);
    $info = $up->getFileInfo();
    if($info['width']>600||$info['height']>1000){
        $srcipt ="<script>alert('图片像素太大，请上传小于1000*600的图片！');</script>";
    }elseif($info['state']=='SUCCESS') {
        $srcipt = <<< HTML
    <script>
    parent.ShowImg('{$info['url']}', {$info['width']}, {$info['height']});
    </script>
HTML;
    }
    else {
        $srcipt = "<script>alert('".$info['state']."');</script>";
    }
}
else if ($step==2) {
    $file = $_REQUEST['imgSrc'];
    $path = Uploader::crop_image($_REQUEST['imgSrc'],$_REQUEST['w'],$_REQUEST['h'],
        $_REQUEST['x'], $_REQUEST['y']);
    if ($path !==false) {
        $res = $mem->update($_SESSION['memberID'], array('headphoto'=>$path));
        if ($res['status']=='ok') {
            $srcipt =  <<< HTML
            <script>alert('头像更新成功');parent.location.href="http://www.12301.cc/home.html";</script>
HTML;

        } else {
            $srcipt = "<script>alert('{$res['msg']}');</script>";
        }
    }
}
//echo "<script>document.domain='www.12301.cc';</script>";
echo $srcipt;